﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using HMS.Security;

namespace HMS.PL
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            //log4net.Config.DOMConfigurator.Configure();
            log4net.Config.XmlConfigurator.Configure();
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

            if (HttpContext.Current.User != null)
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    if (HttpContext.Current.User.Identity is FormsIdentity)
                    {
                        // Get Forms Identity From Current User
                        //FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;

                        //// Create a custom Principal Instance and assign to Current User (with caching)
                        //HMSPrincipal principal = (HMSPrincipal)HttpContext.Current.Cache.Get(id.Name);
                        //if (principal == null)
                        //{
                        //    // Create and populate your Principal object with the needed data and Roles.
                        //    principal = MyBusinessLayerSecurityClass.CreatePrincipal(id, id.Name);
                        //    HttpContext.Current.Cache.Add(
                        //    id.Name,
                        //    principal,
                        //    null,
                        //    System.Web.Caching.Cache.NoAbsoluteExpiration,
                        //    new TimeSpan(0, 30, 0),
                        //    System.Web.Caching.CacheItemPriority.Default,
                        //    null);
                        //}

                        //HttpContext.Current.User = principal;
                    }
                }
            }


        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}